package different.type.adapter;

/**
 * Created by DELL
 * Date: 2019/9/29.
 * Time: 15:50
 */
interface IIntegerValue{
    public int getInteger();
}

class IntegerValue implements IIntegerValue{
    @Override
    public int getInteger() {
        return 5;
    }
}

//类适配器
class ClassAdapter extends IntegerValue{
    public int getInteger(){
        return 2 + super.getInteger();
    }
}

//对象适配器
class ObjectAdapter{
    private IIntegerValue myInt;

    public ObjectAdapter(IIntegerValue myInt) {
        this.myInt = myInt;
    }
    public int getInteger(){
        return 2 + this.myInt.getInteger();
    }
}

public class ClassAndObjectAdapter {
    public static void main(String[] args) {
        System.out.println("***Class and Object Adapter Demo***");
        ClassAdapter ca1 = new ClassAdapter();
        System.out.println("Class Adapter is returning :" + ca1.getInteger());


        ObjectAdapter oa = new ObjectAdapter(new IntegerValue());
        System.out.println("Object Adapter is returning :" + oa.getInteger());
    }
}
